]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: Only call gjs_dumpstack() on warnings from main thread
authorSebastian Keller <skeller@gnome.org>
Wed, 21 Jan 2026 21:54:39 +0000 (22:54 +0100)
committerSimon McVittie <smcv@debian.org>
Mon, 9 Feb 2026 10:10:03 +0000 (10:10 +0000)
The mozjs code called by gjs_dumpstack() does not appear to be thread
safe and was sometimes resulting in crashes when triggered by error
messages from threads other than the main thread. And even when not
crashing, such a backtrace can only be misleading since only the main
thread is executing JS code.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4046>
(cherry picked from commit 23e3e7970f1ef316c0a5bce2dea4872cf1ca5750)
Origin: upstream, 49.4, commit:c481543906d4f843f8aec26029a760ab82e213ef

Gbp-Pq: Name main-Only-call-gjs_dumpstack-on-warnings-from-main-thread.patch

src/main.c

index 99eca3e3c977c882daea66abbff5f4827570aed8..62a284b51893093cb3f5e4c68d95523080515f26 100644 (file)
@@ -52,6 +52,7 @@ enum {
 };
 static int _shell_debug;
 static gboolean _tracked_signals[NSIG] = { 0 };
+static GThread *main_thread;
 
 static void
 shell_dbus_acquire_name (GDBusProxy  *bus,
@@ -384,7 +385,8 @@ default_log_writer (GLogLevelFlags   log_level,
 
   if ((_shell_debug & SHELL_DEBUG_BACKTRACE_WARNINGS) &&
       ((log_level & G_LOG_LEVEL_CRITICAL) ||
-       (log_level & G_LOG_LEVEL_WARNING)))
+       (log_level & G_LOG_LEVEL_WARNING)) &&
+      g_thread_self () == main_thread)
     {
       const char *log_domain = NULL;
 
@@ -611,6 +613,8 @@ main (int argc, char **argv)
   g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
   g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);
 
+  main_thread = g_thread_self ();
+
   context = meta_create_context (WM_NAME);
   meta_context_add_option_entries (context, gnome_shell_options,
                                    GETTEXT_PACKAGE);